package com.pocketsweet.ui.uilib;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import com.pocketsweet.R;

public class RandomColorTagView extends TextView {
	public RandomColorTagView(Context context) {
		super(context);
		// 初始化
		init(context);
	}

	public RandomColorTagView(Context context, AttributeSet attrs) {
		super(context, attrs);

		// 初始化
		init(context);
	}

	private void init(Context context) {
		int[] colors = { R.color.random1, R.color.random2, R.color.random3,
				R.color.random4, R.color.random5, R.color.random6,
				R.color.random7 };
		initBgColor(R.drawable.shape_rectangle_white);
		int random = (int) (Math.random() * 10) % 6;// 0~6随机数
		int textcolor = getResources().getColor(colors[random]);
		this.setTextColor(textcolor);// 设置随机颜色
		FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(
				FlowLayout.LayoutParams.WRAP_CONTENT,
				FlowLayout.LayoutParams.WRAP_CONTENT);
		params.rightMargin = 10;
		params.bottomMargin = 10;
		params.topMargin = 10;
		params.leftMargin = 10;
		this.setLayoutParams(params);
	}

	public void initBgColor(int drawbleColor) {
		this.setBackgroundResource(drawbleColor);

	}

	@SuppressWarnings("unused")
	public void setName(String value) {
		this.setText(value);
	}
}
